﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using KPIS.GERP.GHRMS.DAL;
using KPIS.GERP.GHRMS.DALFactory;
using KPIS.GERP.GHRMS.IDAL;
using KPIS.GERP.GHRMS.IBLL;
using KPIS.GERP.GHRMS.MODEL;

namespace KPIS.GERP.GHRMS.BLL
{
    public sealed class MasEducationQualificationBLL : IMasEducationQualificationBLL
    {
        private static readonly IMasEducationQualificationDAL dal = DataAccess.CreateMasterEducationQualification();

        private MasEducationQualificationInfo quaInfo = new MasEducationQualificationInfo();
        private MasEducationDegreeInfo degreeInfo = new MasEducationDegreeInfo();
        public IList<MasEducationQualificationInfo> ListEducationQualifications()
        {
            return dal.ListEducationQualifications(new MasEducationQualificationInfo(0));
        }
        public IList<MasEducationQualificationInfo> ListEducationQualifications(string EduDegree)
        {
            if (EduDegree.Length > 0)
                degreeInfo.Sequence = Int32.Parse(EduDegree);

            quaInfo.EducationDegree = degreeInfo;
            return dal.ListEducationQualifications(quaInfo);
        }
        public IList<MasEducationQualificationInfo> ListEducationQualificationsBySequence(string Sequence)
        { 
            int Seq = Sequence.Length > 0 ? Int32.Parse(Sequence) : 0;
            return dal.ListEducationQualifications(new MasEducationQualificationInfo(Seq));
        }
        public DataSet LoadEducationQualifications(Nullable<int> Sequence, Nullable<int> EduDegree, string SearchText)
        {
            int Seq = Sequence.HasValue ? (int)Sequence : 0;
            if (EduDegree.HasValue)
            {
                degreeInfo.Sequence = (int)EduDegree;
                quaInfo.EducationDegree = degreeInfo;
            }
            quaInfo.Sequence = Seq;
            quaInfo.strFilter = SearchText;
            return dal.LoadEducationQualifications(quaInfo);
        }
        public void Insert(string Code, string Name, string NameShort, string NameEng, string EduDegree, int CreatedBy)
        {
            if (EduDegree.Length > 0)
                degreeInfo.Sequence = Int32.Parse(EduDegree);
            try
            {
                dal.Insert(new MasEducationQualificationInfo(0, Code, Name, NameEng, NameShort, degreeInfo, "", CreatedBy, 0));
            }
            catch
            {
                throw new Exception("");
            }
        }
        public void Update(int Sequence, string Code, string Name, string NameShort, string NameEng, string EduDegree, int UpdatedBy)
        {
            if (EduDegree.Length > 0)
                degreeInfo.Sequence = Int32.Parse(EduDegree);
            try
            {
                dal.Update(new MasEducationQualificationInfo(Sequence, Code, Name, NameEng, NameShort, degreeInfo, "", 0, UpdatedBy));
            }
            catch
            {
                throw new Exception("");
            }
        }
        public void Delete(int Sequence, int UpdatedBy)
        {
            try
            {
                dal.Delete(Sequence, UpdatedBy);
            }
            catch
            {
                throw new Exception("");
            }
        }
    }
}
